﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace ifunction.Fiddler.Model
{
    /// <summary>
    /// Class RuntimePackage.
    /// </summary>
    public class RuntimePackage
    {
        #region Property

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name.</value>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the key.
        /// </summary>
        /// <value>The key.</value>
        public Guid Key { get; protected set; }

        /// <summary>
        /// Gets or sets the main request.
        /// </summary>
        /// <value>The main request.</value>
        public FiddlerRequest MainRequest { get; set; }

        /// <summary>
        /// Gets or sets the keep session request.
        /// </summary>
        /// <value>The keep session request.</value>
        public FiddlerRequest KeepSessionRequest { get; set; }

        /// <summary>
        /// Gets or sets the keep session interval.
        /// </summary>
        /// <value>The keep session interval.</value>
        public long KeepSessionInterval{ get; set; }

        /// <summary>
        /// Gets or sets the schedule.
        /// </summary>
        /// <value>The schedule.</value>
        public Schedule Schedule { get; set; }

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="RuntimePackage"/> class.
        /// </summary>
        /// <param name="key">The key.</param>
        public RuntimePackage(Guid key)
        {
            this.Key = key;
        }

        public RuntimePackage()
            : this(Guid.NewGuid())
        {
        }

        #endregion

        /// <summary>
        /// To the request package.
        /// </summary>
        /// <returns>RequestPackage.</returns>
        public RequestPackage ToRequestPackage()
        {
            return new RequestPackage
            {
                Key = this.Key,
                Name = this.Name,
                KeepSessionInterval = this.KeepSessionInterval,
                KeepSessionRequestRaw = this.KeepSessionRequest == null ? string.Empty : this.KeepSessionRequest.ToRaw(),
                MainRequestRaw = this.MainRequest == null ? string.Empty : this.MainRequest.ToRaw(),
                Schedule = this.Schedule.ToString()
            };
        }
    }
}
